using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using btnet;

/// <summary>
/// Summary description for edit_styles
/// </summary>
public partial class edit_styles : System.Web.UI.Page
{
    protected DataSet ds;
    protected Security security;

    void Page_Init (object sender, EventArgs e) {ViewStateUserKey = Session.SessionID;}


    void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String footer_label = null;
            if (Application["custom_footer"] != null)
            {
                footer_label = (String)Application["custom_footer"];
            }
            custom_footer_label.Text = footer_label;
        }

	    Util.do_not_cache(Response);
	
	    security = new Security();
	    security.check_security( HttpContext.Current, Security.MUST_BE_ADMIN);

	    ds = btnet.DbUtil.get_dataset(
		    @"select
			    '<a target=_blank href=edit_priority.aspx?id=' + convert(varchar,pr_id) + '>' + pr_name + '</a>' [priority],
			    '<a target=_blank href=edit_status.aspx?id=' + convert(varchar,st_id) + '>' + st_name + '</a>' [status],
			    isnull(pr_style,'') [priority CSS class],
			    isnull(st_style,'') [status CSS class],
			    isnull(pr_style + st_style,'datad') [combo CSS class - priority + status ],
			    '<span class=''' + isnull(pr_style,'') + isnull(st_style,'')  +'''>The quick brown fox</span>' [text sample]
			    from priorities, statuses /* intentioanl cartesian join */
			    order by pr_sort_seq, st_sort_seq;

			    select distinct isnull(pr_style + st_style,'datad')
			    from priorities, statuses;");

	    ArrayList classes_list = new ArrayList();
	    foreach (DataRow dr_styles in ds.Tables[1].Rows)
	    {

		    classes_list.Add("." + (string) dr_styles[0]);
	    }

	    // create path
        string map_path = (string)HttpRuntime.Cache["MapPath"];
	    string path = map_path + "\\custom\\btnet_custom.css";

	    StringBuilder relevant_css_lines = new StringBuilder();

	    ArrayList lines = new ArrayList();
	    if (System.IO.File.Exists(path))
	    {
		    string line;
		    StreamReader stream=File.OpenText(path);
		    while((line = stream.ReadLine()) != null)
		    {
			    for (int i = 0; i < classes_list.Count; i++)
			    {
				    if (line.IndexOf((string)classes_list[i]) > -1)
				    {
					    relevant_css_lines.Append(line);
					    relevant_css_lines.Append("<br>");
					    lines.Add(line);
					    break;
				    }
			    }
		    }
		    stream.Close();
	    }

	    relevant_lines.InnerHtml = relevant_css_lines.ToString();
    }
}